# Contributor: Adrian L Lange <alpine@p3lim.net>
# Contributor: Charles Wimmer <charles@wimmer.net>
# Contributor: Stuart Cardall <developer@it-offshore.co.uk>
# Contributor: Dermot Bradley <dermot_bradley@yahoo.com>
maintainer="Wolfgang Fischer <wdev@posteo.org>"
pkgname=step-certificates
pkgver=0.28.0
pkgrel=0
pkgdesc="Online certificate authority and related tools"
url="https://smallstep.com/certificates/"
arch="all"
license="Apache-2.0"
makedepends="
	bash
	go
	go-bindata
	libcap-utils
	pcsc-lite-dev
	"
checkdepends="openssl-dev"
depends="step-cli"
options="setcap net"
install="$pkgname.pre-install"
subpackages="
	$pkgname-logrotate
	$pkgname-openrc
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/smallstep/certificates/releases/download/v$pkgver/step-ca_$pkgver.tar.gz
	step-ca.confd
	step-ca.initd
	step-ca.logrotate
	"
builddir="$srcdir"

case "$CARCH" in
	# tests on 32bit platforms runs into "Error=cannot allocate memory"
	armhf|armv7|x86) options="$options !check";;
esac

export GOCACHE="${GOCACHE:-"$tmpdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$tmpdir"}"
export GOMODCACHE="${GOMODCACHE:-"$tmpdir/go"}"

build() {
	make build
}

check() {
	go test -trimpath=false ./...
	case "$CARCH" in
		arm*|aarch64|x86_64|riscv64)
			# go-tpm-tools only upported on arm*|aarch64|x86_64|riscv64
			go test -trimpath=false -tags tpmsimulator ./acme
			;;
	esac
}

package() {
	make DESTDIR="$pkgdir" INSTALL_PREFIX=/usr/ install
	setcap cap_net_bind_service=+ep "$pkgdir"/usr/bin/step-ca

	install -m 644 -D "$srcdir"/step-ca.confd "$pkgdir"/etc/conf.d/step-ca
	install -m 755 -D "$srcdir"/step-ca.initd "$pkgdir"/etc/init.d/step-ca

	install -m 644 -D "$srcdir"/step-ca.logrotate "$pkgdir"/etc/logrotate.d/step-ca
}

logrotate() {
	pkgdesc="Online certificate authority and related tools (logrotate configuration)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel logrotate"

	amove etc/logrotate.d/step-ca
}

sha512sums="
03b70fd84753f9cceec94879a5739fdba0c6d40110f1d7bbec799607cf54d270220cea0f9e49d0338f2f7c0ebe0dfd4ada8d6e1a77947168cf3b432ab0023a89  step-certificates-0.28.0.tar.gz
d0e3781b591a049798891a14bf00cb34fb8341bc37b4bed5e0a52ce01386c5c60e29a58fb1cf495404afbd7b443597857bcdd87b68d2f4dd311fed4e038b8ac3  step-ca.confd
96852aa1be8a2b245a8ada15507e06a7a400430267e77a2026b0067e3d65e3b976d729ffa94e85fb5abbfcb1fee57dd795470132f76c1bbb4a0eaffb78845d0c  step-ca.initd
17740fbe3a72f1c9fe4f90dffb368ad4fe6b98a36512ca58614a4bfbc4b6895ecc6daa4a5a78abcd9b1840eb63ce90523d7fa77a2b42da0cf539bf36330c9f32  step-ca.logrotate
"
